package com.ch.demo1;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;

public class demo7 {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(9999);

        Socket socket = serverSocket.accept();

        InputStream inputStream = socket.getInputStream();

        byte[] buf = new byte[1024];
        int str;

        while((str  =inputStream.read(buf)) != -1){
            System.out.println(new String(buf,0,str));
        }

        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = sdf.format(date);
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write(format.getBytes());

        socket.shutdownOutput();
        socket.close();
        inputStream.close();
        outputStream.close();
        serverSocket.close();
    }
}
